MediaLibrary PRO
The MediaLibrary module provides read-only access to the user's local media library, allowing scripts to query songs, albums, artists, and playlists, and retrieve artwork.
Important notes:
- The user must grant permission to access the media library.
- Only items available in the device media library are returned (including locally synced content, iTunes synced content, and downloaded Apple Music tracks).
- All returned data structures are read-only and cannot modify the system library.
Data Models
Item
Represents a single song.
Field descriptions:
title: Song titlepersistentID: Unique local media library identifier (used for playback and artwork retrieval)artist: Performing artistalbumTitle: Album namealbumArtist: Album artistgenre: Genrecomposer: ComposeralbumTrackNumber: Track number within the albumalbumTrackCount: Total track count of the albumdiscNumber: Disc numberdiscCount: Total disc countplaybackDuration: Duration in secondsplaybackStoreID: Apple Music Store ID (if available)isCloudItem: Indicates whether the item is cloud-basedhasProtectedAsset: Indicates DRM-protected content
Playlist
Represents a playlist.
Field descriptions:
persistentID: Unique playlist identifiername: Playlist nametrackCount: Number of tracks
Album
Represents an album.
Field descriptions:
title: Album titleartist: Album artistpersistentID: Album identifier (may be unavailable in some cases)trackCount: Number of tracks
Query Options
SongQueryOptions
Description:
limit: Maximum number of resultssortBy: Field used for sortingascending: Sort order (default is descending if not specified)
AlbumQueryOptions
PlaylistQueryOptions
ArtistQueryOptions
SongFilter
Used to filter song queries.
Notes:
- Supports exact match filtering.
- Multiple fields may be combined.
API Methods
getSongs
Query songs.
Example:
getSongByPersistentID
Retrieve a single song by persistentID.
Example:
getAlbums
Retrieve albums.
Example:
getAlbumSongs
Retrieve songs within a specific album.
Example:
Notes:
- Matching is based on album title.
- If multiple albums share the same name, results may include tracks from all matching albums.
getArtists
Retrieve artist names.
Example:
getArtistSongs
Retrieve songs by a specific artist.
Example:
getPlaylists
Retrieve playlists.
Example:
getPlaylistSongs
Retrieve songs within a playlist.
Example:
getArtwork
Retrieve artwork for a song.
Description:
- Returns a
UIImage. sizespecifies the desired render dimensions.- Returns
nullif artwork is unavailable.
Example:
Best Practices
- Use
limitto control result size for large queries. - For playback workflows, store
persistentIDinstead of entire item objects. - Load artwork on demand rather than preloading in bulk.
- To play songs, combine this module with
SystemMusicPlayer.setQueueByPersistentIDs.
